package com.hippo.core.ui.compose.mine

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import com.hippo.core.R
import com.hippo.core.core.ext.paddingBody
import com.hippo.core.ui.components.ThemeButton
import com.hippo.core.ui.components.VerticalSpacer
import com.hippo.core.ui.theme.HippoTheme

@Composable
fun VersionDialog(modifier: Modifier = Modifier) {

    var showDialog by remember { mutableStateOf(true) }

    if (showDialog) {

        Dialog(onDismissRequest = { showDialog = false }) {
            Column(modifier = Modifier
                .fillMaxWidth()
                .background(Color.White)) {
                Box(
                    modifier = Modifier
                        .fillMaxWidth()
                        .background(
                            color = Color(0xFFF5F5F5),
                            shape = RoundedCornerShape(
                                topStart = 6.dp,
                                topEnd = 6.dp
                            ),
                        )
                        .padding(16.dp)
                ) {
                    Text(
                        text = stringResource(R.string.update_1),
                        style = MaterialTheme.typography.titleMedium,
                        modifier = Modifier.align(Alignment.Center)
                    )

                    IconButton(onClick = { }, modifier = Modifier.align(Alignment.CenterEnd)) {
                        Icon(
                            imageVector = Icons.Default.Close,
                            contentDescription = "Close"
                        )
                    }
                }

                HorizontalDivider(thickness = 0.5.dp)

                Column (
                    modifier = Modifier
                        .fillMaxWidth()
                        .paddingBody()
                ){

                    Column(
                        horizontalAlignment = Alignment.CenterHorizontally,
                        modifier = Modifier.padding(16.dp).fillMaxWidth()
                    ) {

                        Image(
                            painter = painterResource(id = R.mipmap.machine),
                            contentDescription = "AppIcon",
                            modifier = Modifier
                                .size(120.dp)
                                .align(Alignment.CenterHorizontally)
                        )

                        Text(
                            text = "V1.0.0",
                            style = MaterialTheme.typography.bodyLarge,
                            textAlign = TextAlign.Center,
                            modifier = Modifier
                                .fillMaxWidth()
                                .background(
                                    color = Color(0xFFDCE7F3),
                                    shape = RoundedCornerShape(8.dp),
                                )
                                .padding(16.dp)
                        )

                    }

                    VerticalSpacer(30.dp)

                    Text(
                        text = "V1.0.0",
                        style = MaterialTheme.typography.bodyLarge,
                         textAlign = TextAlign.Center,
                        modifier = Modifier
                            .fillMaxWidth()
                            .padding(16.dp)
                    )

                    VerticalSpacer(30.dp)

                    ThemeButton(
                        modifier = Modifier.fillMaxWidth(),
                        text = stringResource(R.string.upgrade),
                        onClick = { showDialog = false }
                    )

                    VerticalSpacer(20.dp)
                }

            }
        }
    }
}


@Preview(showBackground = true)
@Composable
private fun VersionDialogPreview() {
    HippoTheme {
        VersionDialog()
    }
}


